***Replication do file for 
***Cingolani-Fazeksa (2019) The role of agencification in achieving value-for-money in public spending. Governance
***14/10/2019
*******************************
*Please note that due to differences in sorting the dataset minor differences in the numerical results might arise between the replication data and the manuscript. These influence the interpretation of the results in no occassion.




*** analysis: matching ***

global sourcef "C:\Users\mf436\Desktop\ted"

use $sourcef\ted_data_2006_2016_agencification.dta, clear


*** matching for Table 1-2-3 and matching diagnostics in Appendix A (Tables A1-9)

set seed 12345
tempvar sortorder
gen `sortorder' = runiform() if anb_country!="FR"
sort `sortorder'


*savings
psmatch2 agency year2-year11 ca_contract_value52-ca_contract_value56 cpv_div2-cpv_div71 anb_type2-anb_type5 anb_csector2-anb_csector20 ///
if anb_country=="UK" & agency_nrc>10, out(savings) common noreplacement
gen weight_uk_sav=_weight
pstest year2-year11 ca_contract_value52-ca_contract_value56 cpv_div2-cpv_div71 anb_type2-anb_type5 anb_csector2-anb_csector20 ///
 if anb_country=="UK" & agency_nrc>10, both graph

psmatch2 agency year2-year11 ca_contract_value52-ca_contract_value56 cpv_div2-cpv_div71 anb_type2-anb_type5 anb_csector2-anb_csector20 ///
if anb_country=="DE" & agency_nrc>10, out(savings) common noreplacement
gen weight_de_sav=_weight
pstest year2-year11 ca_contract_value52-ca_contract_value56 cpv_div2-cpv_div71 anb_type2-anb_type5 anb_csector2-anb_csector20 ///
 if anb_country=="DE" & agency_nrc>10, both graph

psmatch2 agency year2-year11 ca_contract_value52-ca_contract_value56 cpv_div2-cpv_div71 anb_type2-anb_type5 anb_csector2-anb_csector20 ///
if anb_country=="ES" & agency_nrc>10, out(savings) common noreplacement
gen weight_es_sav=_weight
pstest year2-year11 ca_contract_value52-ca_contract_value56 cpv_div2-cpv_div71 anb_type2-anb_type5 anb_csector2-anb_csector20 ///
 if anb_country=="ES" & agency_nrc>10, both graph

gen weight_sav=weight_es_sav
replace weight_sav=weight_de_sav if weight_sav==.
replace weight_sav=weight_uk_sav if weight_sav==.



*bidder nr
psmatch2 agency year2-year11 ca_contract_value52-ca_contract_value56 cpv_div2-cpv_div71 anb_type2-anb_type5 anb_csector2-anb_csector20 ///
if anb_country=="UK" & agency_nrc>10, out(bidnr_trim) common noreplacement
gen weight_uk_nbr=_weight
pstest year2-year11 ca_contract_value52-ca_contract_value56 cpv_div2-cpv_div71 anb_type2-anb_type5 anb_csector2-anb_csector20 ///
 if anb_country=="UK" & agency_nrc>10, both graph

psmatch2 agency year2-year11 ca_contract_value52-ca_contract_value56 cpv_div2-cpv_div71 anb_type2-anb_type5 anb_csector2-anb_csector20 ///
if anb_country=="DE" & agency_nrc>10, out(bidnr_trim) common noreplacement
gen weight_de_nbr=_weight
pstest year2-year11 ca_contract_value52-ca_contract_value56 cpv_div2-cpv_div71 anb_type2-anb_type5 anb_csector2-anb_csector20 ///
 if anb_country=="DE" & agency_nrc>10, both graph

psmatch2 agency year2-year11 ca_contract_value52-ca_contract_value56 cpv_div2-cpv_div71 anb_type2-anb_type5 anb_csector2-anb_csector20 ///
if anb_country=="ES" & agency_nrc>10, out(bidnr_trim) common noreplacement
gen weight_es_nbr=_weight
pstest year2-year11 ca_contract_value52-ca_contract_value56 cpv_div2-cpv_div71 anb_type2-anb_type5 anb_csector2-anb_csector20 ///
 if anb_country=="ES" & agency_nrc>10, both graph

gen weight_nrb=weight_es_nbr
replace weight_nrb=weight_de_nbr if weight_nrb==.
replace weight_nrb=weight_uk_nbr if weight_nrb==.
 
 
*decision period
psmatch2 agency bidnr_trim year2-year11 ca_contract_value52-ca_contract_value56 cpv_div2-cpv_div71 anb_type2-anb_type5 anb_csector2-anb_csector20 ///
if anb_country=="UK" & agency_nrc>10, out(decp_trim) common noreplacement logit
gen weight_uk_decp=_weight
pstest bidnr_trim ca_contract_value52-ca_contract_value56 cpv_div2-cpv_div71 anb_type2-anb_type5 anb_csector2-anb_csector20 ///
 if anb_country=="UK" & agency_nrc>10, both graph

psmatch2 agency bidnr_trim year2-year11 ca_contract_value52-ca_contract_value56 cpv_div2-cpv_div71 anb_type2-anb_type5 anb_csector2-anb_csector20 ///
if anb_country=="DE" & agency_nrc>10, out(decp_trim) common noreplacement
gen weight_de_decp=_weight
pstest bidnr_trim year2-year11 ca_contract_value52-ca_contract_value56 cpv_div2-cpv_div71 anb_type2-anb_type5 anb_csector2-anb_csector20 ///
 if anb_country=="DE" & agency_nrc>10, both graph

psmatch2 agency bidnr_trim year2-year11 ca_contract_value52-ca_contract_value56 cpv_div2-cpv_div71 anb_type2-anb_type5 anb_csector2-anb_csector20 ///
if anb_country=="ES" & agency_nrc>10, out(decp_trim) common noreplacement
gen weight_es_decp=_weight
pstest bidnr_trim year2-year11 ca_contract_value52-ca_contract_value56 cpv_div2-cpv_div71 anb_type2-anb_type5 anb_csector2-anb_csector20 ///
 if anb_country=="ES" & agency_nrc>10, both graph

gen weight_decp=weight_es_decp
replace weight_decp=weight_de_decp if weight_decp==.
replace weight_decp=weight_uk_decp if weight_decp==.


***Table 1


*savings
reg savings i.agency i.qanb_country if agency_nrc>10 & anb_country!="FR", base
margins, at(agency=(0 1))
reg savings i.agency i.qanb_country if weight_sav==1 & anb_country!="FR", base
margins, at(agency=(0 1))

*bidder nr
reg bidnr_trim i.agency i.qanb_country if agency_nrc>10 & anb_country!="FR", base
margins, at(agency=(0 1))
reg bidnr_trim i.agency i.qanb_country if weight_nrb==1 & anb_country!="FR", base
margins, at(agency=(0 1))

*decision period
reg decp_trim i.agency i.qanb_country if agency_nrc>10 & anb_country!="FR", base
margins, at(agency=(0 1))
reg decp_trim i.agency i.qanb_country if weight_decp==1 & anb_country!="FR", base
margins, at(agency=(0 1))


***Table 2


*young agencies
reg savings i.agency i.qanb_country if agency_nrc>10 & anb_country!="FR" & agency_age_cat!=3, base
margins, at(agency=(0 1))
reg savings i.agency i.qanb_country if weight_sav==1 & anb_country!="FR" & agency_age_cat!=3, base
margins, at(agency=(0 1))

*old agencies
reg savings i.agency i.qanb_country if agency_nrc>10 & anb_country!="FR" & agency_age_cat!=1 & agency_age_cat!=2, base
margins, at(agency=(0 1))
reg savings i.agency i.qanb_country if weight_sav==1 & anb_country!="FR" & agency_age_cat!=1 & agency_age_cat!=2, base
margins, at(agency=(0 1))

save $sourcef\ted_data_2006_2016_agencification.dta, replace


***Table 3

*savings
ttest savings if weight_uk_sav==1, by(agency)
ttest savings if weight_de_sav==1, by(agency)
ttest savings if weight_es_sav==1, by(agency)

*bidder number
ttest bidnr_trim if weight_uk_nbr==1, by(agency)
ttest bidnr_trim if weight_de_nbr==1, by(agency)
ttest bidnr_trim if weight_es_nbr==1, by(agency)

*decision period
ttest decp_trim if weight_uk_decp==1, by(agency)
ttest decp_trim if weight_de_decp==1, by(agency)
ttest decp_trim if weight_es_decp==1, by(agency)




***CEM for Appendix B and CEM diagnostics (Tables B4-5-6)


*savings

use $sourcef\ted_data_2006_2016_agencification.dta, clear

keep if agency_nrc>10 | agency_nrc==.
keep if year !=.
keep if ca_cpv_div!=.
keep if anb_type!=.
keep if ca_contract_value5!=.
keep if savings!=.
keep if anb_csector!=.

cem year(#11) ca_cpv_div (#42) anb_type(#5) anb_csector(#20) qanb_country(#4) ca_contract_value5(#6), showbreaks treatment(agency)

keep if cem_matched==1

save $sourcef\ted_data_2006_2016_agencification_cem_sav.dta,  replace


*bidnr_trim

use $sourcef\ted_data_2006_2016_agencification.dta, clear

keep if agency_nrc>10 | agency_nrc==.
keep if year !=.
keep if ca_cpv_div!=.
keep if anb_type!=.
keep if ca_contract_value5!=.
keep if bidnr_trim!=.
keep if anb_csector!=.

cem year(#11) ca_cpv_div (#42) anb_type(#5) anb_csector(#20) qanb_country(#4) ca_contract_value5(#6), showbreaks treatment(agency)

keep if cem_matched==1

save $sourcef\ted_data_2006_2016_agencification_cem_bidnr.dta,  replace


*decision period

use $sourcef\ted_data_2006_2016_agencification.dta, clear

keep if agency_nrc>10 | agency_nrc==.
keep if year !=.
keep if ca_cpv_div!=.
keep if anb_type!=.
keep if ca_contract_value5!=.
keep if decp_trim!=.
keep if bidnr_trim!=.
keep if anb_csector!=.

cem bidnr_trim(0 1.5 5.5 10.5 20) year(#11) ca_cpv_div (#42) anb_type(#5) anb_csector(#20) qanb_country(#4) ca_contract_value5(#6), showbreaks treatment(agency)

keep if cem_matched==1

save $sourcef\ted_data_2006_2016_agencification_cem_decp.dta,  replace


***Appendix B: Table B1 (CEM)


use $sourcef\ted_data_2006_2016_agencification_cem_sav.dta, clear
reg savings i.agency i.qanb_country [aweight=cem_weights] if anb_country!="FR", base
margins, at(agency=(0 1))

use $sourcef\ted_data_2006_2016_agencification_cem_bidnr.dta
reg bidnr_trim i.agency i.qanb_country [aweight=cem_weights] if anb_country!="FR", base
margins, at(agency=(0 1))

use $sourcef\ted_data_2006_2016_agencification_cem_decp.dta, clear
reg decp_trim i.agency i.qanb_country [aweight=cem_weights] if anb_country!="FR", base
margins, at(agency=(0 1))


*Appendix B: Table B2 (CEM)


use $sourcef\ted_data_2006_2016_agencification_cem_sav.dta, clear

reg savings i.agency i.qanb_country [aweight=cem_weights] if agency_nrc>10 & anb_country!="FR" & agency_age_cat!=3, base
margins, at(agency=(0 1))
reg savings i.agency i.qanb_country [aweight=cem_weights] if agency_nrc>10 & anb_country!="FR" & agency_age_cat!=1 & agency_age_cat!=2, base
margins, at(agency=(0 1))


*Appendix B: Table B3 (CEM)


*savings
use $sourcef\ted_data_2006_2016_agencification_cem_sav.dta, clear
reg savings i.agency [aweight=cem_weights] if anb_country=="UK"
margins, at(agency=(0 1))
reg savings i.agency [aweight=cem_weights] if anb_country=="DE"
margins, at(agency=(0 1))
reg savings i.agency [aweight=cem_weights] if anb_country=="ES"
margins, at(agency=(0 1))

*bidder number
use $sourcef\ted_data_2006_2016_agencification_cem_bidnr.dta, clear
reg bidnr_trim i.agency [aweight=cem_weights] if anb_country=="UK"
margins, at(agency=(0 1))
reg bidnr_trim i.agency [aweight=cem_weights] if anb_country=="DE"
margins, at(agency=(0 1))
reg bidnr_trim i.agency [aweight=cem_weights] if anb_country=="ES"
margins, at(agency=(0 1))

*decision period
use $sourcef\ted_data_2006_2016_agencification_cem_decp.dta, clear
reg decp_trim i.agency [aweight=cem_weights] if anb_country=="UK"
margins, at(agency=(0 1))
reg decp_trim i.agency [aweight=cem_weights] if anb_country=="DE"
margins, at(agency=(0 1))
reg decp_trim i.agency [aweight=cem_weights] if anb_country=="DE" & anb_csector!=10 & anb_csector!=11, base
margins, at(agency=(0 1))
reg decp_trim i.agency [aweight=cem_weights] if anb_country=="ES"
margins, at(agency=(0 1))



